
<cfparam name="path" default="Z:\,x:\,s:\" >
<cfparam name="r" default="true" >
<cfloop list="#path#" index="d">
<cfset newName="">
<cfset lastProg=-1>
	<script language="javascript">
 
        top.document.getElementById("progressBar").style.width='<cfoutput>50</cfoutput>px';
        top.document.getElementById("per").innerHTML='<cfoutput>10% </cfoutput>';
    </script>
    <script>top.document.getElementById("txt").innerHTML='Started Scanning <cfoutput>#d#</cfoutput>. this may take a while';</script>
    <cfdirectory action="list"  directory="#d#" name="scan" recurse="#r#" filter="*.ogm|*.jpg|*.avi|*.flv|*.mpg|*.wmv|*.mp4|*.mp3|*.mpeg" />
   <cfif not scan.recordcount>
		<script>
            top.document.getElementById("progressBar").style.width='<cfoutput>#100*progressWidth#</cfoutput>px';
            top.document.getElementById("per").innerHTML='<cfoutput>100% </cfoutput>';
        </script>
        <script>top.document.getElementById("txt").innerHTML='Completed Scanning <cfoutput>#d#</cfoutput>. No file found';</script>
   <cfelse>
		<script>
            top.document.getElementById("progressBar").style.width='<cfoutput>250</cfoutput>px';
            top.document.getElementById("per").innerHTML='<cfoutput>50% </cfoutput>';
        </script>
		<script>top.document.getElementById("txt").innerHTML='Completed Scanning <cfoutput>#d#</cfoutput>. Indexing started';</script>
    </cfif>
    
    
    <cfloop query="scan" > 
    <cfif size neq 0>
		<cfif not FindNoCase('#VideoThumbPath#',DIRECTORY)>
            <cfprocessingdirective suppressWhiteSpace="true">
				<cfset prog=((currentrow*100) / recordcount) >
               
                <script>
                    top.document.getElementById("progressBar").style.width='<cfoutput>#Round(prog)*progressWidth#</cfoutput>px';
                    top.document.getElementById("per").innerHTML='<cfoutput>#Round(prog)#% #currentrow# of #recordcount#</cfoutput>';
                </script>
                 <cfif lastProg neq #Round(prog)#></cfif>
                 
                <cftry>
                
                <cfquery  datasource="101tf2">
                
                insert into scan (id,date,dir,name,size) values ('#createuuid()#',#DATELASTMODIFIED#,"#PreserveSingleQuotes(replace(DIRECTORY,'\','\\','ALL'))#",'#name#','#size#')
                </cfquery>
                    <script>top.document.getElementById("txt").innerHTML='<cfoutput>adding - #JSStringFormat(name)#</cfoutput>';</script><cfif lastProg neq #Round(prog)#></cfif>
                    
                <cfcatch type="database" >
                 
                <script>top.document.getElementById("txt").innerHTML='<cfoutput>#JSStringFormat(name)# already added.</cfoutput>';</script><cfif lastProg neq #Round(prog)#></cfif>
                
                </cfcatch>
                
                </cftry>
                
                <cfset lastProg=#Round(prog)#> 
                <cfset newName=ListAppend(newName,name)>
            </cfprocessingdirective>
        </cfif> 
        <cfflush>
    </cfif>    
    </cfloop>
            
        <cfif scan.recordcount>
          <cfoutput>
          <cfquery  datasource="101tf2" name="sync"> select * from  scan where  name NOT IN (#PreserveSingleQuotes(ListQualify(replace(newName,"'","''","ALL"),"'"))#)   
        and dir like <cfqueryparam cfsqltype="cf_sql_varchar" value="#replace(d,'\','\\','ALL')#%"></cfquery> </cfoutput>
        
        <cfloop query="sync">
			<cfif not FileExists("#dir#\#name#")>
            	<cfquery  datasource="101tf2" name="syncdel"> delete from scan where id = '#id#'</cfquery>
            </cfif>
        </cfloop>
        </cfif>
        
</cfloop>